package logic

import (
	"context"
	"day1/video/rpc/videoclient"
	"net/http"

	"day1/video/api/internal/svc"
	"day1/video/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdateLogic) Update(req *types.Updaterequest) (resp *types.Updateresponse, err error) {
	// todo: add your logic here and delete this line
	_, err = l.svcCtx.VideoRpc.Update(context.Background(), &videoclient.UpdateRequest{
		Path:    req.Path,
		Version: int64(req.Version),
		Name:    req.Name,
	})
	if err != nil {
		return &types.Updateresponse{
			Code: -1,
			Msg:  err.Error(),
		}, nil
	}
	return &types.Updateresponse{
		Code: http.StatusOK,
		Msg:  "success",
	}, nil
}
